<?php


namespace App\Http\Controllers\cms;


use App\Engine\BaseController;
use App\Http\Validate\SysValidate;
use App\Models\Sys as SysConfigModel;
use function app\Utils\go;

class Sys extends BaseController
{
    /**获取配置信息
     * @return array
     */
    public function get()
    {
        $res=SysConfigModel::get();
        $arr=array();
        $flas=[false,true];
        foreach ($res as $key=>$v){
            if($v['switch']==2){
                $v['value']=(int)$v['value'];
            }
            if($v['switch']==1){
                $v['value']=$flas[$v['value']];
            }

            $arr[$v['type']][]=$v;
        }
        return go($arr);
    }

    /**添加配置信息
     * @return array
     * @throws \Illuminate\Validation\ValidationException
     */
    public function insert()
    {
        $this->validate($this->request,SysValidate::$rule,SysValidate::$message);
        return go(SysConfigModel::insert_data($this->post));
    }

    /**更新配置信息
     * @return array
     * @throws \App\Exceptions\ApiException
     */
    public function update()
    {
        return go(SysConfigModel::update_data($this->post));
    }

}
